package com.transsnet.mybatis.base;

import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableId;
import lombok.Data;

import java.io.Serializable;
import java.util.List;
import java.util.stream.Collectors;

@Data
public class BaseEntity implements Serializable, Cloneable {
    @TableId(value = "id", type = IdType.AUTO)
    private Long id;

    public String getObfuscatedId() {
        return (ObfuscatedId.getObfuscatedId(getId()));
    }

    public static <T extends BaseEntity> List<Long> toIdList(List<T> entities) {
        return entities.stream().map(BaseEntity::getId).collect(Collectors.toList());
    }

    @Override
    public BaseEntity clone() {
        try {
            return (BaseEntity) super.clone();
        } catch (CloneNotSupportedException e) {
            throw new RuntimeException(e);
        }
    }
}
